// Test case for bufMap.cpp

#include <iostream>
#include "bufMap.h"

using namespace std;


int main() {

	BufMap *map = new BufMap();
	
    /* We're not actually valid file handles!  Don't use us! */
    File *f1 = (File*)(0xDEADBEEF);
    File *f2 = (File*)(0xF00DBEEF);
    File *f3 = (File*)(0xBADBEEF);
    File *f4 = (File*)(0xF9390FF);

	map->insert(f1,17,(unsigned int)170);
	map->insert(f2,17,(unsigned int)230);
	map->insert(f3,39,(unsigned int)390);
    
    Status errStatus = map->insert(f3,39,(unsigned int)390);
    if(errStatus != BUFMAPERROR) {
        cout << "Buffer Map returned the wrong error status!" << endl;
    } 
    else {
        cout << "Buffer Map handled insert error correctly." << endl;
    }

	unsigned int f1FrameNo = -1;
	unsigned int f2FrameNo = -1;
	unsigned int f3FrameNo = -1;
    unsigned int f4FrameNo = -1;

	map->lookup(f1,17,f1FrameNo);
	map->lookup(f2,17,f2FrameNo);
	map->lookup(f3,39,f3FrameNo);

	cout << "File 1's frame number = " << f1FrameNo << "\texpected = 170" << endl;
	cout << "File 2's frame number = " << f2FrameNo << "\texpected = 230" << endl;
	cout << "File 3's frame number = " << f3FrameNo << "\texpected = 390" << endl;

    errStatus = map->lookup(f4,4,f4FrameNo);
    if(errStatus != BUFMAPNOTFOUND) {
        cout << "Buffer Map returned the wrong error status!" << endl;
    }
    else {
        cout << "Buffer Map handled lookup error correctly." << endl;
    }
    
    errStatus = map->remove(f4,4);
    if(errStatus != BUFMAPNOTFOUND) {
        cout << "Buffer Map returned the wrong error status!" << endl;
    }
    else {
        cout << "Buffer Map handled remove error correctly." << endl;
    }

	return 0;
}
